package NodeList;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class removeElements {
    public ListNode removeElements(ListNode head, int val) {
        if (head == null){
            return null;
        }
        while (head != null && head.val == val){
            head = head.next;
        }
        ListNode node = head;
        ListNode next;
        while (node != null){
            next= node.next;
            if (next != null && next.val == val){
                node.next = next.next;
            } else {
                node = node.next;
            }
        }
        return head;
    }
}
